//
//  JLJobTableViewController.m
//  JLStyleApp
//
//  Created by LvJianfeng on 15/8/22.
//  Copyright (c) 2015年 JLStyle. All rights reserved.
//

#import "JLJobTableViewController.h"
#import "JLCreateJobMegViewController.h"

@interface JLJobTableViewController ()
@property (strong, nonatomic) NSMutableArray *data;
@end

@implementation JLJobTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"选择行业";
    
    [self setupRightBarItem];
}

- (void)cancelAction{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.data.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *Identifier = @"JobCell";
    JLJobCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
    if (cell==nil) {
        cell = [[JLJobCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier];
    }
    cell.jobNameLabel.text = self.data[indexPath.row];
    return cell;
}

#pragma mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *chooseText = self.data[indexPath.row];
    [self.delegate jobPassValue:chooseText];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self dismissViewControllerAnimated:YES completion:nil];
    });
}

#pragma mark setupRightBarItem

- (void)setupRightBarItem{
    UIButton *doneButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
    doneButton.titleLabel.font = JLFont(15);
    [doneButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [doneButton setTitleColor:[UIColor customLightPlaceColor] forState:UIControlStateHighlighted];
    [doneButton setTitle:@"取消" forState:UIControlStateNormal];
    [doneButton addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithCustomView:doneButton];
    self.navigationItem.rightBarButtonItem = rightBarItem;
}

#pragma mark lazyload
- (NSMutableArray *)data{
    if (_data==nil) {
        _data = [[NSMutableArray alloc] init];
        NSString *path = [[NSBundle mainBundle] pathForResource:@"Business" ofType:@"plist"];
        NSArray *dataArray = [[NSArray alloc] initWithContentsOfFile:path];
        if (dataArray) {
            _data = [dataArray copy];
        }
    }
    return _data;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

@implementation JLJobCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle     = UITableViewCellSelectionStyleNone; //点击无背景
        self.backgroundColor    = [UIColor clearColor];
        UILabel *cityNameLabel  = [[UILabel alloc] init];
        cityNameLabel.frame         = CGRectMake(20, 50/2-20, ScreenWidth-35, 40);
        [self addSubview:cityNameLabel];
        self.jobNameLabel    = cityNameLabel;
    }
    return self;
}
@end
